1.最簡單的流程控制control flow
2 == 2 True >>> 2 == 5 False
2 != 5 True >>> 2 != 2 False
2 < 5 True >>> 5 < 2 False
2 <= 2 True >>> 5 <= 2 False
5 > 2 True >>> 2 > 5 False
5 >= 5 True >>> 2 >= 5 False
2.布林值Boolean operators
布林值的運算符號有三種
• and
例如
1 < 2 and 2 < 3 is True;
1 < 2 and 2 > 3 is False.
• or
例如
1 < 2 or 2 > 3 is True;
1 > 2 or 2 > 3 is False.
• Not
例如
not 41 > 40 傳回 False.
資料來源:https://www.codecademy.com/courses/learn-python/lessons/conditionals--control-flow/exercises/to-be-andor-not-to-be?action=resume_content_item
布林值的運算並不是左至右,其固定順序是
3.Conditional Statement Syntax條件語句
例子1:
例子2:
if, else語句
elif
“else if”的簡寫
例子: